package com.yeyaomai.dksns.flowis.servlet;

import java.io.StringWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.mongodb.core.query.Order;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.yeyaomai.dksns.flowis.dao.UserReturnRateDao;
import com.yeyaomai.dksns.flowis.dao.VisitDepthDao;
import com.yeyaomai.dksns.flowis.domain.UserReturnRate;
import com.yeyaomai.dksns.flowis.domain.VisitDepth;
import com.yeyaomai.dksns.flowis.domain.flowisdetail.FlowisQueryOrder;
import com.yeyaomai.dksns.flowis.domain.flowisdetail.FlowisStatDetailDTO;
import com.yeyaomai.dksns.flowis.service.FlowisQueryService;
import com.yeyaomai.dksns.flowis.service.UserReturnRateService;
import com.yeyaomai.dksns.flowis.service.VisitDepthService;
import com.yeyaomai.dksns.flowis.servlet.dto.AjaxResult;
import com.yeyaomai.dksns.flowis.util.Globals;

/**
 * @author dingtao@yeyaomai.com
 */
@Controller
@RequestMapping("/loyalty/*")
public class CustomerLoyaltyController {

	private static Logger logger = LoggerFactory.getLogger(CustomerLoyaltyController.class);
	// 用户访问深度
	@Autowired
	private UserReturnRateService userReturnRateService;
	// 用户回头率
	@Autowired
	private VisitDepthService visitDepthService;

	private static ObjectMapper objectMapper = new ObjectMapper();

	@RequestMapping(value = "/user-return-rate")
	public ModelAndView userReturnRate(HttpServletRequest request, HttpServletResponse response,
			FlowisQueryOrder order, ModelMap modelMap) {
		ModelAndView mav = new ModelAndView("return-rate");

		List<UserReturnRate> userReturnRateList = userReturnRateService.getByDate("2012-05-12", "2012-06-23");
		// 获取当天的数据

		mav.addObject("userReturnRateList", userReturnRateList);
		return mav;
	}

	@RequestMapping(value = "/user-visit-depth")
	public ModelAndView userVisitDepth(HttpServletRequest request, HttpServletResponse response,
			FlowisQueryOrder order, ModelMap modelMap) {
		ModelAndView mav = new ModelAndView("visit-depth");

		List<VisitDepth> visitDepthServiceList = visitDepthService.getByDate("2012-05-12", "2012-06-23");

		mav.addObject("visitDepthServiceList", visitDepthServiceList);
		return mav;
	}
}
